package gnss

/// 信号->频段ID(1--8)
/*
The new codes for GPS L2C/L5 and Galileo codes are introduced as follows:

 +---------------------------------------------------------------------------+
 | System  Freq.Band  Frequency           RINEX 2-character Code             |
 |                              Ps.Range  Carr.Phase  Doppler  Sign.Strength |
 +---------------------------------------------------------------------------+
 | GPS     L1         1575.42     C1,P1       L1         D1         S1       |
 |         L2         1227.60     C2,P2       L2         D2         S2       |
 |         L5         1176.45      C5         L5         D5         S5       |
 |                                                                           |
 | Glonass G1         1602+k*9/16 C1,P1       L1         D1         S1       |
 |         G2         1246+k*7/16 C2,P2       L2         D2         S2       |
 |                                                                           |
 | Galileo E2-L1-E1   1575.42      C1         L1         D1         S1       |
 |         E5a        1176.45      C5         L5         D5         S5       |
 |         E5b        1207.140     C7         L7         D7         S7       |
 |         E5a+b      1191.795     C8         L8         D8         S8       |
 |         E6         1278.75      C6         L6         D6         S6       |
 |                                                                           |
 | SBAS    L1         1575.42      C1         L1         D1         S1       |
 |         L5         1176.45      C5         L5         D5         S5       |
 +---------------------------------------------------------------------------+


*/
func Sign2Rinex2xID(satsys byte, sigv byte) byte {
	if satsys == SYS_GPS {
		if sigv <= 1 {
			return 0
		} else if sigv >= 2 && sigv <= 4 { //2..4   L1
			return 1
		} else if sigv == 8 { //2..4   L2
			return 2
		} else if sigv >= 9 && sigv <= 10 { //9..10 L2
			return 2
		} else if sigv >= 15 && sigv <= 17 { //15..17 L2
			return 2
		} else if sigv >= 22 && sigv <= 24 { //22..24 L5
			return 2
		} else if sigv >= 30 && sigv <= 32 { //30..32 L1
			return 1
		}
	} else if satsys == SYS_BD {
		if sigv <= 1 { // 未知
			return 0
		} else if sigv >= 2 && sigv <= 4 { //2..4   I, Q, I+Q  B1(一期)
			return 1
		} else if sigv <= 7 { // 5..7   B1C  北斗三的新信号  (应该是保留的)  20180205-iGMAS-T11TAC008-03V4.0_RTCM协议.pdf(进行了定义)
			return 0
		} else if sigv <= 10 { // 8...10
			return 3
		} else if sigv <= 13 { // 11..13   // "B3C"   北斗三的新信号
			return 0
		} else if sigv <= 16 { // 14..16  // "B2"
			return 2
		} else if sigv <= 19 { // 17..19    // B2a    北斗三的新信号
			return 0
		} else if sigv <= 22 { // 20..22   // "B2b"   北斗三的新信号
			return 0
		} else if sigv <= 25 { // 23..25    B2(B2a+B2b)
			return 0
		} else if sigv >= 26 && sigv <= 31 { // 26..31  B1C  北斗三的新信号
			return 0
		}
	} else if satsys == SYS_GAL {
		if sigv <= 1 {
			return 0
		} else if sigv >= 2 && sigv <= 6 { //2..6   E1
			return 1
		} else if sigv >= 8 && sigv <= 12 { //8..12 E6
			return 6
		} else if sigv >= 14 && sigv <= 16 { //14..16 E5B
			return 7
		} else if sigv >= 18 && sigv <= 20 { //18..20 E5(A+B)
			return 8
		} else if sigv >= 22 && sigv <= 24 { //22..24 E5A
			return 5
		}
	} else if satsys == SYS_GLO {
		if sigv <= 1 {
			return 0
		} else if sigv >= 2 && sigv <= 3 { //2..3   G1
			return 1
		} else if sigv >= 8 && sigv <= 9 { //8..9  G2
			return 2
		}
		return 0
	}

	return 0
}
